package com.icinema.server.factories;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.KeyFactory;
import com.icinema.vo.Cinema;
import com.icinema.vo.Movie;
import com.icinema.vo.MovieShowing;
import com.icinema.vo.Rating;
import com.icinema.vo.User;

public class EntityFactory <T>{
	public T toCinema(Entity entity){
		Cinema cinema = new Cinema();
		cinema.setId(KeyFactory.keyToString(entity.getKey()));
		cinema.setName((String)entity.getProperty("name"));
		cinema.setManager((String)entity.getProperty("manager"));
		cinema.setAddress((String)entity.getProperty("address"));
		cinema.setPhone((String)entity.getProperty("phone"));
		cinema.setSeatCapacity((Long)entity.getProperty("seatCapacity"));
		return (T)cinema;
	}
	public T toUser(Entity entity){
		User user = new User();
		user.setId(KeyFactory.keyToString(entity.getKey()));
		user.setEmail((String)entity.getProperty("email"));
		user.setPassword((String)entity.getProperty("email"));
		return (T)user;
	}
	public T toMovie(Entity entity){
		Movie movie = new Movie();
		movie.setId(KeyFactory.keyToString(entity.getKey()));
		movie.setName((String)entity.getProperty("name"));
		movie.setRatingId((String)entity.getProperty("ratingId"));
		return (T)movie;
	}
	public T toRating(Entity entity){
		Rating rating = new Rating();
		rating.setId(KeyFactory.keyToString(entity.getKey()));
		rating.setName((String)entity.getProperty("name"));
		return (T)rating;
	}
	public T toMovieShow(Entity entity){
		MovieShowing movieShowing = new MovieShowing();
		movieShowing.setShowingFromDate((String)entity.getProperty("showingFromDate"));
		movieShowing.setShowingToDate((String)entity.getProperty("showingToDate"));
		movieShowing.setCinemaId((String)entity.getProperty("cinemaId"));
		movieShowing.setMovieId((String)entity.getProperty("movieId"));
		movieShowing.setId(KeyFactory.keyToString(entity.getKey()));
		return (T)movieShowing;
	}
}
